#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
void order(int* min, int* mid, int* max)
{
    int t = 0;
    if (*max < *mid)
    {
        t = *max;
        *max = *mid;
        *mid = t;
    }
    if (*max < *min)
    {
        t = *max;
        *max = *min;
        *min = t;
    }
    if (*mid < *min)
    {
        t = *mid;
        *mid = *min;
        *min = t;
    }
}

int re_order(int n, int* min, int* mid, int* max)
{
    if (n / 10 == 0)
    {
        *max = n;
        *mid = 0;
        *min = 0;
    }
    else if (n / 10 < 10)
    {
        *max = n / 10;
        *mid = n % 10;
        *min = 0;
    }
    else
    {
        *max = n / 100;
        *mid = n / 10 % 10;
        *min = n % 10;
    }
}

int combine(int x, int y, int z)
{
    return x * 100 + y * 10 + z;
}

int main()
{
    int n;
    scanf("%d", &n);
    int counter = 0;
    while (n != 495)
    {
        int min, mid, max;
        re_order(n, &min, &mid, &max);
        order(&min, &mid, &max);
        int a = combine(max, mid, min);
        int b = combine(min, mid, max);
        n = a - b;
        counter++;
        printf("%d: %d - %d = %d\n", counter, a, b, n);
    }
    return 0;
}
